<!-- 生成后端空页面 -->
<template>
    <div>
        <el-form ref="dataForm" :model="dataForm" :rules="rules" label-width="80px" style="width: 30%; margin-top: 30px">
            <el-form-item label="类名:" prop="ClassName">
                <el-input placeholder="请输入类名: 例如: HelloWorld"
                          prefix-icon="el-icon-search"
                          v-model="dataForm.ClassName" clearable />
            </el-form-item>
            <el-form-item label="注释:" prop="Chinese">
                <el-input placeholder="请输入注释: 例如: 你好世界"
                          prefix-icon="el-icon-search"
                          v-model="dataForm.Chinese" clearable />
            </el-form-item>
            <el-form-item label="实体:" prop="EntityName">
                <el-input placeholder="请输入实体: 例如: HelloWorldEntity"
                          prefix-icon="el-icon-search"
                          v-model="dataForm.EntityName" clearable />
            </el-form-item>
            <el-form-item label="路径:" prop="path">
                <el-autocomplete v-model="dataForm.path"
                        :fetch-suggestions="querySearch"
                        placeholder="请输入或选择controller文件夹项目路径"
                        style="width: 200%"/>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit('dataForm')">立即创建</el-button>
                <el-button>帮助</el-button>
            </el-form-item>
        </el-form>

    </div>
</template>

<script>

  import {apiDefaultErrorHandler} from "../../api/base";
  import baseApi from "../../api/operation/base";
  import {deepCopy} from "../../utils";

  export default {
    name: "emptyend",

    data() {
      return {
        allPath: [],
        dataForm: {
          ClassName: '',
          path: '',
          EntityName: '',
          Chinese: ''
        },
        rules: {
          ClassName: [
            { required: true, message: '请输入类名称', trigger: 'blur' },
          ],
          path: [
            { required: true, message: '请输入路径', trigger: 'blur' }
          ],
          EntityName: [
            { required: true, message: '请输入实体名称', trigger: 'blur' }
          ],
          Chinese: [
            { required: true, message: '请输入注释', trigger: 'blur' }
          ]
        },
        search: {}
      };
    },
    mounted() {
      this.allPath = this.loadAll();
    },
    methods: {
      querySearch(queryString, cb) {
        var allPath = this.allPath;
        var results = queryString ? allPath.filter(this.createFilter(queryString)) : allPath;
        // 调用 callback 返回建议列表的数据
        cb(results);
      },
      createFilter(queryString) {
        return (restaurant) => {
          return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
        };
      },
      onSubmit(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.makeFile();
          } else {
            this.$message('On No!!');
          }
        });
      },
      makeFile() {
        this.search = deepCopy(this.dataForm)
        baseApi.makeEndFile(this.search).then(({data}) => {
          if (this.$http.isResponseSuccess(data)) {
            this.$message('成成成功!!');
          } else {
            apiDefaultErrorHandler(data)
          }
        }).catch((ex) => {
          apiDefaultErrorHandler(ex)
        })
      },
      openTxt() {
        translateApi.openTxt().then(({data}) => {
          if (this.$http.isResponseSuccess(data)) {
            this.$message('打开成功!');
          } else {
            this.$message('打开失败!');
            apiDefaultErrorHandler(data)
          }
        }).catch((ex) => {
          apiDefaultErrorHandler(ex)
          this.$message('打开失败!');
        })
      },
      loadAll() {
        return [
          { "value": "D:\\workspace\\abandon-me\\server\\src\\main\\java\\operation\\modules\\operation\\controller" },
          { "value": "C:\\Users\\86132\\Desktop\\svn\\OneMES\\2.src\\trunk\\1.Web\\Server\\mes-server\\mes-base-server\\src\\main\\java\\mes\\base\\modules\\dip\\controller\\CheckItemController.java" },
          { "value": "C:\\Users\\86132\\Desktop\\svn\\OneFixture\\2.src\\trunk\\1.Web\\Server\\fixture-server\\fixture-base-server\\src\\main\\java\\fixture\\base\\modules\\fixture\\controller" }
        ]
      }
    }
  }
</script>

<style scoped>

</style>